package be.ipl.pigolo.testUcc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.junit.Before;
import org.junit.Test;

import be.ipl.pigolo.domaine.Partie;
import be.ipl.pigolo.usecases.GestionPartie;

public class TestGetEtat {

	private Partie p;

	private static GestionPartie gp;

	@Before
	public void setUp() throws Exception {
		try {
			Context jndi = new InitialContext();
			gp = (GestionPartie) jndi
					.lookup("ejb:PigoloEAR/PigoloEJB/GestionPartieImpl!be.ipl.pigolo.usecases.GestionPartie");
			assertNotNull(gp);
		} catch (NamingException e) {
			e.printStackTrace();
		}

	}
	@Test
	public void testEtatEnAttente() {
		p = new Partie("partie7",5);
		this.gp.creerPartie(p.getNom(), 30);
		assertEquals(Partie.Etat.EN_ATTENTE, p.getEtat());
	}

	@Test
	public void testEtatEnCours() {
		p = new Partie("partie8",5);
		this.gp.creerPartie(p.getNom(), 30);
		this.p.commencerPartie();
		assertEquals(Partie.Etat.EN_COURS, p.getEtat());
	}

	@Test
	public void testEtatTerminee() {
		p = new Partie("partie9",5);
		this.gp.creerPartie(p.getNom(), 30);
		this.p.commencerPartie();
		this.p.terminerPartie();
		assertEquals(Partie.Etat.TERMINEE, p.getEtat());
	}

}
